﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Xml.Serialization;
using System.Xml;

namespace ShevaEngine.Core
{
    /// <summary>
    /// Sheva engine settings.
    /// </summary>
    public class ShevaEngineSettings
    {
        /// <summary>Singleton.</summary>
        public static readonly ShevaEngineSettings Instance = ShevaEngineSettings.LoadSettings();

        /// <summary>Dynamic resolution.</summary>
        public Boolean DynamicResolution;
        /// <summary>Backbuffer width.</summary>
        public Int32 BackbufferWidth;
        /// <summary>Backbuffer height.</summary>
        public Int32 BackbufferHeight;


        /// <summary>
        /// Constructor.
        /// </summary>
        private ShevaEngineSettings()
        {
            this.DynamicResolution = true;
            this.BackbufferWidth = 800;
            this.BackbufferHeight = 600;            
        }

        /// <summary>
        /// Method loads sheva engine settings.
        /// </summary>
        /// <returns></returns>
        private static ShevaEngineSettings LoadSettings()
        {
            ShevaEngineSettings output = null;

            string filename = "ShevaEngine.cfg";

            if (File.Exists(filename))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(ShevaEngineSettings));

                using (XmlReader reader = XmlReader.Create(filename))
                    output = serializer.Deserialize(reader) as ShevaEngineSettings;
            }

            if (output == null)
            {
                output = new ShevaEngineSettings();                
            }

            return output;
        }
    }
}
